//useSelector用来获取数据，useDispatch用来分发action对象
import { useSelector ,useDispatch} from "react-redux";
//导入action，用来修改数据
import {increment,decrement} from './store/slices/countSlice'
import {stuState} from './store/slices/studentSlice'
import {fetchStudent} from './store/slices/asyncSlice'
function App() {
  let count = useSelector(state => {
    return state.countSlice.count
  })
  let myState = useSelector(params => {
    return params.stuSlice.state
  })
  const dispatch = useDispatch()
  const handleIn = () => {
    dispatch(increment(10))
  }
  const handleDe = () => {
    dispatch(decrement(5))
  }
  const handleChangeState = (some) => {
    return () => {
      dispatch(stuState(some))
    }
  }

  let data = useSelector(state => {
    console.log(state)
  })
  const handleSync = async () => {
    dispatch(fetchStudent())
  }
  return (
    <div>
        <p>计数器：{count}</p>
        <p>状态值为：{myState?1:0}</p>
        <button onClick={handleIn}>+</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <button onClick={handleDe}>-</button>
        <button onClick={handleChangeState(true)}>点我改变状态为true</button>
        <button onClick={handleChangeState(false)}>点我改变状态为false</button>
        <button onClick={handleSync}>点我打印异步数据</button>
    </div>
  );
}
export default App;
